LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;

ENTITY LoadMap123 IS
	PORT(
		Clk : IN std_logic;
		Start : IN std_logic;
		Finish : OUT std_logic;
		Reset : IN std_logic;
		
		GameMode : IN std_logic_vector(1 downto 0);
		GameMap : IN std_logic_vector(1 downto 0);

		PrimAddr    : OUT std_logic_vector(9 downto 0);
		PrimReadData    : IN  std_logic_vector(23 downto 0);
		SecoAddr   : OUT std_logic_vector(9 downto 0);
		SecoWriteData   : OUT std_logic_vector(23 downto 0);
		SecoWriteEnable : OUT std_logic;
		SecoReadData    : IN  std_logic_vector(23 downto 0)
	);
END LoadMap123;

ARCHITECTURE rtl OF LoadMap123 IS
--	TYPE State_Type IS (Idle,
--						LoadMap,
--						GameLooping,
--						MapLooping,
--						UpdateMap_Load,
--						UpdateMap_Calculate,
--						UpdateMap_Store,
--						StoreMap,
--						StoreMap_Wait,
--						Pausing,
--						GameOver
--						);
--	
--	SIGNAL state, bakstate : State_Type;
--	SIGNAL sCounter : std_logic_vector(3 downto 0);
--	
--	--SIGNAL Pausing : std_logic;
--	SIGNAL SUp, SDown, SLeft, SRight, SCenter : std_logic_vector(23 downto 0);
--	SIGNAL NCenter : std_logic_vector(23 downto 0);
--	SIGNAL PosX, PosY : std_logic_vector(4 downto 0);
--	SIGNAL DataLoadStart, DataLoadFinish : std_logic;
--	SIGNAL LoadMapStart, LoadMapFinish : std_logic;
--	SIGNAL CalcCellStart, CalcCellFinish : std_logic;
--	SIGNAL CalcCellFlag : std_logic;
BEGIN
--	PROCESS(Clk, Reset)
--	BEGIN
--		IF Reset = '1' THEN
--			state <= idle;
--		ELSIF rising_edge(Clk) THEN
--			CASE state IS
--				WHEN Idle =>
--					Finish <= '0';
--					IF Start = '1' THEN
--						state <= GameLooping;
--					ELSE
--						state <= Idle;
--					END IF;
--				WHEN GameLooping =>
--					IF GameMode = "11" THEN
--						state <= StoreMap;
--						--TODO.....
--					ELSE
--						state <= LoadMap;
--						LoadMapStart <= '1';
--					END IF;
--				WHEN LoadMap =>
--					IF LoadMapFinish = '1' THEN
--						state <= MapLooping;
--						PosX <= "00000";
--						PosY <= "00001";
--					END IF;
--					LoadMapStart <= '0';
--				WHEN MapLooping =>
--					PrimWriteEnable <= '0';
--					IF PosX = 25 THEN
--						IF PosY = 18 THEN
--							state <= StoreMap;
--							PosX <= "00000";
--							PosY <= "00001";
--						ELSE
--							PosX <= 1;
--							PosY <= PosY +1;
--							state <= UpdateMap_Load;
--							DataLoadStart <= '1';
--						END IF;
--					ELSE
--						PosX <= PosX +1;
--						state <= UpdateMap_Load;
--						DataLoadStart <= '1';
--					END IF;
--				WHEN UpdateMap_Load =>
--					DataLoadStart <= '0';
--					IF DataLoadFinish = '1' THEN
--						state <= UpdateMap_Calculate;
--						CalcCellStart <= '1';
--					END IF;
--				WHEN UpdateMap_Calculate =>
--					CalcCellStart <= '0';
--					IF CalcCellFinish = '1' THEN						
--						IF CalcCellFlag = '1' THEN
--							state <= GameOver;
--						ELSE
--							state <= UpdateMap_Store;
--							SecoWriteAddr <= PosY & PosX;
--							SecoWriteEnable <= '1';
--							SecoWriteData <= NCenter;
--							sCounter <= 0;
--						END IF;
--					END IF;
--				WHEN UpdateMap_Store =>
--					IF sCounter = 2 THEN
--						SecoWriteEnable <= '0';
--						state <= MapLooping;
--					ELSE
--						sCounter <= sCounter +1;
--					END IF;
--				WHEN StoreMap =>
--					IF PosX = 25 THEN
--						IF PosY = 18 THEN
--							state <= GameLooping;
--						ELSE
--							PosX <= 1;
--							PosY <= PosY +1;
--							state <= StoreMap_Wait;
--							sCounter <= 0;
--						END IF;
--					ELSE
--						PosX <= PosX +1;
--						state <= StoreMap_Wait;
--						sCounter <= 0;
--					END IF;
--				WHEN StoreMap_Wait =>
--					IF sCounter = 5 THEN
--						state <= StoreMap;
--					ELSE
--						sCounter <= sCounter +1;
--					END IF;
--				WHEN GameOver =>
--					Finish <= '1';
--					state <= idle;
--				WHEN Pausing =>
--					--IF Input
--				WHEN OTHERS =>
--			END CASE;
--		END IF;
--	END PROCESS;
END rtl;
